<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta http-equiv="x-dns-prefetch-control" content="on">
    <!-- <meta http-equiv="X-Frame-Options" content="ALLOW-FROM"> -->
    <title>填写收货地址</title>
    <link rel="stylesheet" href="./lib/css/jquery-weui.min.css" />
    <link rel="stylesheet" href="./style/base.css" />
    <link rel="stylesheet" href="./style/layer.css" />
</head>

<body>
    <div class="fixed bg2"></div>
    <div class="content_jgg">
        <div class="content address-content">
            <div class="container">
                <div class="form-item">
                    <label>姓名</label>
                    <div>
                        <input data-code="receiverName" type="text" id="name">
                    </div>
                </div>
                <div class="form-item">
                    <label>联系电话</label>
                    <div>
                        <input data-code="receiverPhone" type="tel" id="tel">
                    </div>
                </div>
                <div class="form-item">
                    <label>地址</label>
                    <div class="arrow">
                        <input class="input-pch" data-code="city" type="text" placeholder="请选择城市" id="city">
                    </div>
                </div>
                <div class="form-item">
                    <label>门牌号</label>
                    <div>
                        <input data-code="detailAddress" type="text" id="address">
                    </div>
                </div>
                <div class="form-item t-c">
                    <button class="gradient-bg" id="submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <div class="loading-bar hidden"> </div>
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/js/jquery-weui.min.js"></script>
    <script>
        function loading(isOpen) {
            $('.loading-bar')[isOpen ? 'removeClass' : 'addClass']('hidden');
        }
        loading(1);
    </script>
    <script type="text/javascript" src="./lib/js/city_new.min.js"></script>
    <script type="text/javascript" src="./lib/js/cityPicker.js"></script>
    <!-- <script type="text/javascript" src="./js/common.js?v=20180719"></script> -->
    <script type="text/javascript" src="./js/layer.m.js"></script>
    <script>

        var urlSplit = window.location.href.split("/");
        var info = JSON.parse(localStorage.getItem('isLogin') || '{}');
        var common = {
            prize: {},
            urlPage: 'http://127.0.0.1:5500/static',
            url: 'http://192.168.14.187:8090',
            // url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4],
            skipUrl: 'https://live.polyv.cn/watch/239952',
        };
        $(function () {
            loading();
            var city = cityData;
            $("#city").cityPicker({
                title: "请选择收货地址",
                raw: city
            });
        })
        var t = +new Date();

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return r[2];
            return null;
        }

        $('#submit').on('click', function (e) {
            var codes = $('#city').attr('data-codes');
            var codeArr = codes ? codes.split(',') : [];
            var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
            var params = {
                cardNo: info.staffNum,
                receiverName: $('#name').val(),
                receiverPhone: $('#tel').val(),
                provinceCode: codeArr[0],
                cityCode: codeArr[1],
                townCode: codeArr[2],
                detailAddress: $('#address').val()
            }
            var msg = "";
            for (var k in params) {
                if (!params[k]) {
                    if (k == 'provinceCode' || k == 'cityCode' || k == 'townCode') {
                        msg = $('[data-code="city"]').closest('.form-item').find('label').text() + '不能为空！';
                    } else {
                        msg = $('[data-code=' + k + ']').closest('.form-item').find('label').text() + '不能为空！';
                    }
                    break;
                }
                if (k == 'receiverName' && params[k].length > 10) {
                    msg = '姓名长度不能超过10位！';
                    break;
                }
                if (k == 'receiverPhone' && !reg.test(params[k])) {
                    msg = '联系电话格式不正确！';
                    break;
                }
                if (k == 'detailAddress' && params[k].length > 100) {
                    msg = '门牌号长度不能超过100！';
                    break;
                }
            }
            if (msg) {
                layer.open({
                    type: 3,
                    title: '温馨提示',
                    className: 'errortNotice',
                    content: '<div class="notice">' + msg + '</div><div class="button">确定</div>',
                    style: 'width:17rem; background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                    shadeClose: false,
                });
                $(".errortNotice  .button").on("click", function () {
                    layer.closeAll();
                })
            } else {
                var t = +new Date();
                var urlSplit = window.location.href.split("/");
                $.ajax({
                    // url: common.url + "/auldraw/address/create",
                    url: window.location.protocol + "//" + window.location.host + "/" + urlSplit[3] + "/" + urlSplit[4] + "/auldraw/address/create",
                    type: 'POST',
                    data: JSON.stringify({
                        dealerNo: JSON.parse(localStorage.getItem("isLogin")).staffNum,
                        receiverName: $('#name').val(),
                        receiverPhone: $('#tel').val(),
                        provinceCode: codeArr[0],
                        cityCode: codeArr[1],
                        townCode: codeArr[2],
                        detailAddress: $('#address').val(),
                        qualiSeqNo: getQueryString("qualiSeqNo"),
                    }),
                    contentType: 'application/json;charset=UTF-8',
                    dataType: 'json',
                    // header: {
                    //     "Content-Type": "application/json",
                    // },
                    beforeSend: function () {
                        loading(1);
                    },
                    complete: function () {
                        loading();
                    },
                    success: function (data) {
                        if (data && data.code == 0) {
                            layer.open({
                                title: '&nbsp;',
                                className: 'drawNotice',
                                content: '<div class="zjnotice t-c">' + data.content +
                                    '</div><div class="button">' + '返回直播' + '</div>',
                                style: 'width:17rem;background-color:#fff; border:none;border-radius:6px;box-shadow: 0px 0px 15px #000000;',
                                shadeClose: false,
                                end: function () {
                                    location.href = common.skipUrl;
                                }
                            });
                            $(".drawNotice  .button").on("click", function () {
                                layer.closeAll();
                            })
                        }
                    },
                    error: function (err) {

                    },

                })
            }
        })
    </script>
    <style>
        #cnzz_stat_icon_1275024165 {
            display: none;
        }
    </style>
    <script type="text/javascript">
        var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
        document.write(unescape("%3Cspan id='cnzz_stat_icon_1275024165'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol +
            "s19.cnzz.com/z_stat.php%3Fid%3D1275024165' type='text/javascript'%3E%3C/script%3E"));
    </script>
</body>

</html>